﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OneShoppingDAL;
using OneShoppingBLL;
using OneShoppingUtility;
using OneShoppingModel;

public partial class Backstage_Pages_sysmng_personalInfo : BasePage
{
    int uid;
    int roleid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (role.RoleId > 2 || role.RoleId <1)
        {
            Response.Redirect("../../login.html");
        }
        uid = user.UserId;
        roleid = user.RoleId;
        if (!IsPostBack)
        {
            roleid = user.RoleId;
            switch (roleid)
            {
                case 1:
                    CompanyUser c = CompanyUserBLL.GetInstance().GetEntity(r => r.UserId == uid);
                    name.Text = c.RealName;
                    email.Visible = false;
                    text_email.Visible = false;
                    stroename.Visible = false;
                    text_stroename.Visible = false;
                    break;
                case 2:
                    BusinessUser b = BusinessUserBLL.GetInstance().GetEntity(r => r.UserId == uid);
                    name.Text = b.UserName;
                    email.Text = b.Email;
                    stroename.Text = b.StroeName;
                    break;
            }
        }
    }

    //保存按钮
    protected void btnSave_Click(object sender, EventArgs e)
    {
        switch (roleid)
        {
            case 1:
                CompanyUser c = CompanyUserBLL.GetInstance().GetEntity(r => r.UserId == uid);
                c.RealName = name.Text;
                bool rc = CompanyUserBLL.GetInstance().Update(c);
                if (!rc)
                {
                    UtilityMessageBox.Show(this, "更新失败");
                    return;
                }
                break;
            case 2:
                BusinessUser b = BusinessUserBLL.GetInstance().GetEntity(r => r.UserId == uid);
                b.UserName = name.Text;
                b.StroeName = stroename.Text;
                b.Email = email.Text;
                bool rb = BusinessUserBLL.GetInstance().Update(b);
                if (!rb)
                {
                    UtilityMessageBox.Show(this, "更新失败");
                    return;
                }
                break;
        }
        UtilityMessageBox.Show(this, "更新成功");
    }
}